package com.example.mapper;

import com.example.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Mapper
public interface EmpMapper {

    /*
    * 分页查询
    * */
    public List<Emp> list(@Param("name") String name, @Param("gender")Short gender,
                          @Param("begin") LocalDate begin, @Param("end") LocalDate end);

    /*
    * 删除员工
    * */
    //@Delete("delete from emp where id = #{ids}")
    void delete(@Param("ids") List<Integer> ids);

    @Insert("insert into emp(id, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "VALUE(#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime}) ")
    void insert(Emp emp);

    @Select("select * from emp where id = #{id}")
    Emp getByID(Integer id);

    @Update("update emp set username = #{username},name = #{name},gender = #{gender}, job = #{job}, " +
            "entrydate = #{entrydate}, dept_id = #{deptId} where id = #{id}")
    void upDate(Emp emp);



    @Select("select * from emp where username =#{username} and password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);


    /*
    * 根据部门ID来删除部门下的员工
    * */
    @Delete("delete from emp WHERE dept_id =#{deptid}")
    void deleteBydeptid(Integer deptid);
}
